package com.jarvis.hospital.prescription.adapter;

import android.text.TextUtils;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jarvis.hospital.R;
import com.jarvis.hospital.prescription.model.BloodTimeModel;
import com.jarvis.hospital.prescription.model.PrescriptionDetailModel;

import java.util.List;

/**
 * Created by jarvis.liu on 9/12/2016.
 */
public class AllPrescriptionAdapter extends BaseQuickAdapter<PrescriptionDetailModel> {
    private int type;

    public AllPrescriptionAdapter(int layoutResId, List<PrescriptionDetailModel> data, int type) {
        super(layoutResId, data);
        this.type = type;
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, PrescriptionDetailModel prescriptionDetailModel) {
        baseViewHolder
                .setText(R.id.tv_time, prescriptionDetailModel.getCreateTime())
                .setText(R.id.tv_patient_bed_no, prescriptionDetailModel.getPatientBedNumber())
                .setText(R.id.tv_patient_name, prescriptionDetailModel.getPatientName())
                .setText(R.id.tv_MTXdose, prescriptionDetailModel.getMTXdose()+"mg")
                .setText(R.id.tv_MTXDuration, prescriptionDetailModel.getMTXTimeDuration()+"h")
                .setText(R.id.tv_CFdose, prescriptionDetailModel.getCFdose()+"mg")
                .setText(R.id.tv_CFInterval, prescriptionDetailModel.getCFTimeInterval()+"h");
        TextView tv_status = baseViewHolder.getView(R.id.tv_status);
        TextView tv_blood = baseViewHolder.getView(R.id.tv_blood);
        TextView tv_patient_sex = baseViewHolder.getView(R.id.tv_patient_sex);
        if (type == 0) {
            //tv_status.setText("未审核");
        } else if (type == 1) {
            tv_status.setText("已审核");
            tv_status.setTextColor(mContext.getResources().getColor(R.color.green));
        } else if (type == 2) {
            tv_status.setText("退回");
            tv_status.setTextColor(mContext.getResources().getColor(R.color.red));
        } else if (type == -1) {
            tv_status.setText("结束");
        }
        if("0".equals(prescriptionDetailModel.getPatientSexuality())){
            tv_patient_sex.setText("女");
        }else {
            tv_patient_sex.setText("男");
        }
        List<BloodTimeModel> listBloodTime = prescriptionDetailModel.getListBloodTime();
        String blood_inf="";
        for (int i = 0; i < listBloodTime.size(); i++) {
            BloodTimeModel bloodTimeModel = listBloodTime.get(i);
            if("1".equals(bloodTimeModel.getBloodIsSelect())){
                if(TextUtils.isEmpty(blood_inf)){
                    blood_inf = "给药起" + bloodTimeModel.getBloodInterval() + "h";
                }else {
                    blood_inf = blood_inf + ",给药起" + bloodTimeModel.getBloodInterval() + "h";
                }
            }
        }
        tv_blood.setText(blood_inf);

    }
}
